function UnitUsedAbilityWithDelta takes unit caster , integer abilityId , real delta returns nothing
	local integer abilityMasteryId = abilityId.masteryId
	local real mastery = caster.abilityMasteryId
	local real newMastery = mastery + delta
	local integer abilityLevelNow = GetUnitAbilityLevel(caster , abilityId)
	local hashtable levelMasteryTable = abilityId.levelMasteryTable
	local integer maxLevel = abilityId.maxLevel
	local boolean levelUp = false
	local integer nextAbility = abilityId.nextAbility
	local player owner = GetOwningPlayer(caster)
	local hashtable casterAvailableAbilityTable = owner.abilityAvailableTable
	//--
	set caster.abilityMasteryId = newMastery
	loop
		if abilityLevelNow < maxLevel then
			if newMastery >= levelMasteryTable[abilityLevelNow][0] then
				set abilityLevelNow = abilityLevelNow + 1
				set levelUp = true
			else
				exitwhen true
			endif
		else
			exitwhen true
		endif
	endloop
	
	if levelUp then
		call SetUnitAbilityLevel(caster , abilityId , abilityLevelNow)
		call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIlm\\AIlmTarget.mdl" , caster , "origin"))
	endif
	
	if abilityId.NEXT_ABILITY.exists() and LoadBoolean(casterAvailableAbilityTable , nextAbility , StringHash("LEARNED")) == false and newMastery >= LoadReal(masteryTable , maxLevel , 0) then
		call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\Levelup\\LevelupCaster.mdl" , caster , "origin"))
		call SaveBoolean(casterAvailableAbilityTable , nextAbility , StringHash("LEARNED") , true)
		call SetPlayerAbilityAvailable(owner , nextAbility , true)
		call SetPlayerAbilityAvailable(owner , GetDefaultAbility(LoadInteger(udg_AbilityDataHashTable , nextAbility , StringHash("HOTKEY"))) , false)
		call PrintP(owner , "你學會了" + LoadStr(udg_AbilityDataHashTable , nextAbility , StringHash("NAME")) + "!")
		call PrintP(owner , "輸入 -s" + FakeHotkeyToRealHotkey(LoadInteger(udg_AbilityDataHashTable , nextAbility , StringHash("HOTKEY"))) + " 可以在武器技能與初始技能間切換")
	endif
endfunction

ability WindSlash 'A021'
	data
		constant integer hotkey = StringHash("W")
		constant integer masteryId = windSlashMastery
		constant string name = "迴旋斬"	
		constant integer maxLevel = 3
		constant real levels[1].levelUpExperience = 2.0
		constant real levels[2].levelUpExperience = 4.0
		constant real levels[3].levelUpExperience = 6.0
	enddata
	
	action
		call UnitPlayAnimation(caster , 63 , 2.5 , 0.4)
		timerstart ONCE 0.2
			local unit caster = GetTriggerUnit()
			local real mastery = caster.windSlashMastery
			local integer abilityLevel = GetUnitAbilityLevel(caster , WindSlash)
			local item weapon = GetWeaponOfType(caster , StringHash("TWO_HANDED"))
			local real weaponDamage = weapon.damage
			local real damage = 20.0 + weaponDamage * 0.1 * mastery
			//--
			for unit whichTarget in UnitsInRangeOfXY(200.0 , caster.x , caster.y)
				if IsUnitEnemy(whichTarget , GetOwningPlayer(caster)) and not IsUnitType(whichTarget , UNIT_TYPE_STRUCTURE) and GetUnitState(whichTarget , UNIT_STATE_LIFE) > 0.0 then
					call UnitDamageTarget(caster , whichTarget , damage , true , false , ATTACK_TYPE_NORMAL , DAMAGE_TYPE_COLD , WEAPON_TYPE_METAL_MEDIUM_SLICE)
				endif
			endfor
			call UnitUsedAbilityWithDelta(caster , WindSlash , 1.0)
		endtimerstart
	endaction
endability